This article provides step-by-step instructions on how to set up a new Rust project, integrate the Ditto SDK, cross-compile for any target platform, and more:
rustup
:
rustup
command, install it via the official Install Rust documentation.rustup
, ensure it’s updated to the latest version:rustc
and cargo
available in your shell:Cargo.toml
file located in the root of your project, add a dependency on dittolive-ditto
. We recommend using the "=x.y.z"
semver syntax to prevent implicit upgrades.rust-toolchain
file next to your Cargo.toml
and paste the Rust toolchain version you looked up from the compatibiltiy mapCargo.toml
and rust-toolchain
files, then check that you can build and run the executable with cargo run
:cargo build
or cargo run
after updating the rust-toolchain
file, you should see the “info: syncing channel updates” message. This is rustup
magically installing the toolchain you specified in rust-toolchain
behind the scenes.Component | Best Practice |
---|---|
AppRoot/AppExecutable | The executable file for your app that, unless explicitly specified, the Ditto SDK is statically linked to: - All other files and directories should be relative to this location. - Maintain a clear separation between this executable file and other libraries. - If desired, use the Ditto SDK as a separate shared library. (See Optional Dynamic Linking) |
AppRoot/libdittoffi.dll | The Ditto SDK binary library file linking your Cargo for Rust project with Ditto.¹ By default, the Ditto SDK is statically linked to your executable. However, if desired, you can configure your build for dynamic linking by specifying the shared library version of the Ditto SDK. (See Optional Dynamic Linking) |
AppRoot/ditto_data/ | The base directory designated for Ditto-backed app data stored locally on the end-user device: - Organize all app data within this directory rather than across the entire filesystem for your project. - Maintain a clear and consistent directory structure for your project. |
.dylib
for macOS and .dll
for Windows. (See Binary Library Path Formats)
libdittoffi.dylib
) for compilation, use @executable_path
to specify a relative path from the executable to the library:Target | Format | Description |
---|---|---|
Linux | .so | Shared object (SO) |
macOS | .dylib | Dynamic library (DL) |
Windows | .dll | Dynamic link library (DLL) |
build.rs
script failed to locate and download the native static library (dittoffi
) containing the Ditto binary appropriate for your target:
build.rs
script that executes at build is responsible for setting up your build environment and ensuring necessary dependencies, including the Ditto SDK, are correctly configured and accessible for compilation.
However, several factors, such as connectivity issues and misconfigured settings, can cause this script to fail.
To diagnose this issue, check the following logs for errors:
file
, otool
, and readelf
, as follows, inspect the downloaded library located in the build cache to determine if its properties meet the requirements for integration into your Rust project:cargo build
and ensuring it executes successfully.